<template>
	<view class="myTeam">
		<!-- 用户信息 -->
		<view class="userInfo flex-r-c-c"
			style="background-image: url(https://yft.yangfatang.cn/upload/bg/bg2.png); background-size: 100% 100%;">
			<image :src="type == 1 ? myTeamData.userimg : userData.userimg" mode=""></image>
			<view class="list_r flex-r-b-c">
				<view class="list_r_l">
					<view class="name">{{ type == 1 ? myTeamData.nickname : userData.nickname}}</view>
					<!-- <view class="titleBtn">{{myTeamData.identity}}</view> -->
					<view class="titleBtn">会员</view>
					<view class="time">{{ type == 1 ? myTeamData.createtime : userData.createtime}}</view>
				</view>
				<view class="list_r_r">
					<view>我的上级：{{ type == 1 ? myTeamData.mysuperior : userData.topName}}</view>
					<view style="margin-top: 20rpx;">下级人数：{{ type == 1 ? myTeamData.subordinates : userData.num}}人</view>
				</view>
			</view>
		</view>
		<!-- 筛选 -->
		<view class="screenBox flex-r-a-c">
			
			<view class="list flex-r-c-c">
				<picker mode="selector" :range="relationship" range-key="name"  @change="relationshipData">
					<view>{{relationshipText}}</view>
				</picker>
				<u-icon style="margin-left: 10rpx;" name="arrow-down" size="30" color="#ACACAC"></u-icon>
			</view>
			
			<view class="list flex-r-c-c" v-if="type == 1">
				<!-- <picker mode="selector" :range="agentList" range-key="rank" @change="gradeData"> -->
					<view>暂无</view>
				<!-- </picker> -->
				<!-- <view>{{gradeText}}</view> -->
				<!-- <u-icon style="margin-left: 10rpx;" name="arrow-down" size="30" color="#ACACAC"></u-icon> -->
			</view>
			
			<view class="list flex-r-c-c" v-else >
				<picker mode="selector" :range="agentList" range-key="rank" @change="gradeData">
					<view>{{gradeText}}</view>
				</picker>
				<!-- <view>{{gradeText}}</view> -->
				<u-icon style="margin-left: 10rpx;" name="arrow-down" size="30" color="#ACACAC"></u-icon>
			</view>
			
		</view>
		<!-- 下级列表 -->
		<view class="subordinate">
			<view class="list flex-r-a-c" v-for="(item,index) in type == 1 ? myTeamList : agentListData" :key="index" @tap.stop="go(item.id)">
				<view class="list_l">
					<image v-if="item.mobile != null" src="/static/mine/wdtddh.png" mode="" @tap.stop="dialMobile(item.mobile)"></image>
				</view>
				<view class="list_c flex-r-s-c">
					<image :src="item.userimg" mode=""></image>
					<view class="list_c_r">
						<!-- <view class="name">{{item.nickname}}({{item.idcrode}}  {{item.rank}})</view> -->
						<view class="name">{{item.nickname}}</view>
						<view class="time">{{item.createtime}}</view>
					</view>
				</view>
				<view class="list_r">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			
			<view class="text" style="width: 100%; text-align: center; font-size: 32rpx; font-weight: bold;">{{titleText}}</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: null,  // 1 代表 分销中心, 2 代表 代理中心
				page: 1, // 页码
				userData: {}, // 代理中心我的团队
				agentListData: [], // 代理中心数据列表
				myTeamData: {}, // 我的团队数据
				myTeamList: [], // 我的团队列表
				relationship: [ // 推荐关系的筛选
					{
						name: '全部',
						id: 1
					},{
						name: '直推',
						id: 2
					},{
						name: '间推',
						id: 3
					}
				],
				relationshipId: 1,
				gradeText: '代理等级', // 代理等级
				relationshipText: '推荐关系', // 推荐关系
				agentList: [],
				agentId: '',
				titleText: '', // 上拉提示
			};
		},
		onLoad(el) {
			console.log(el)
			// 获取我的团队数据
			this.type = el.type
			this.AgentIdentityList() // 获取级别的列表
			el.type == 1 ? this.getMyTeamData() : this.getAgentTeamData()
		},
		onReachBottom() {
			let that = this
			if(that.titleText == ''){ // 防止上拉多次请求
				that.page = that.page+1
				that.type == 1 ? that.getMyTeamData() : that.getAgentTeamData()
			}
		},
		methods:{
			// 获取级别的列表
			AgentIdentityList(){
				let that = this
				that.$api.getAgentGrade().then(res => {
					console.log(res)
					that.agentList = res.data.data
					that.agentList.push({id: 1, rank: '分享人'},{id: '', rank: '全部'})
				})
			},
			// 获取代理团队数据
			getAgentTeamData(){
				let that = this
				that.$api.agent_myTeam({page:that.page, type: that.relationshipId, level: that.agentId}).then(res => {
					console.log(res)
					that.userData = res.data.data.user
					that.titleText = res.data.data.list.length == 0 ? '暂无数据' : ''
					that.agentListData = that.agentListData.concat(res.data.data.list)
				})
			},
			// 获取我的团队数据
			getMyTeamData(){
				let that = this
				that.$api.myTeam_data({page: that.page ,keyword: that.relationshipId}).then(res => {
					that.myTeamData = res.data.data
					that.titleText = res.data.data.userlists.data.length == 0 ? '暂无数据' : ''
					that.myTeamList = that.myTeamList.concat(res.data.data.userlists.data)
				})
			},
			// 关系的筛选
			relationshipData(e){
				let i = e.detail.value
				this.page = 1
				this.relationshipText = this.relationship[i].name
				this.relationshipId = this.relationship[i].id
				this.myTeamList = []
				this.agentListData = []
				// this.getMyTeamData()
				this.type == 1 ? this.getMyTeamData() : this.getAgentTeamData()
			},
			// 等级筛选
			gradeData(e){
				let i = e.detail.value
				this.page = 1
				this.gradeText = this.agentList[i].name
				this.agentId = this.agentList[i].id
				this.myTeamList = []
				this.agentListData = []
				// this.getAgentTeamData()
				this.type == 1 ? this.getMyTeamData() : this.getAgentTeamData()
			},
			// 拨打电话
			dialMobile(mobile){
				uni.makePhoneCall({
				    phoneNumber: mobile
				});
			},
			// 跳转下级业绩
			go(id){
				uni.navigateTo({
					url: '/distribution/subordinatePage/subordinatePage?id=' + id + '&type=' + this.type
				})
			}
		}
	}
</script>

<style lang="less">
	.myTeam {
		.userInfo {
			width: 90vw;
			height: 208rpx;
			margin: 30rpx auto;

			image {
				width: 120rpx;
				height: 120rpx;
				margin-right: 20rpx;
			}

			.list_r {
				width: 65%;

				.list_r_l {
					.name {
						font-size: 32rpx;
						font-weight: 500;
						color: #292929;
					}

					.titleBtn {
						width: 120rpx;
						height: 42rpx;
						line-height: 42rpx;
						text-align: center;
						border-radius: 30rpx;
						background: linear-gradient(180deg, #FCD8A0 0%, #EABD6E 100%);
						color: #4B4B4B;
						font-size: 24rpx;
						font-weight: 500;
						margin-top: 10rpx;
					}

					.time {
						font-size: 20rpx;
						font-weight: 500;
						color: #888888;
						margin-top: 10rpx;
					}
				}

				.list_r_r {
					color: #4B4B4B;
					font-size: 24rpx;
					font-weight: 500;
				}
			}
		}

		//
		.screenBox {
			width: 90vw;
			height: 180rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			margin: 20rpx auto;

			.list {
				width: 45%;
				height: 132rpx;
				background-color: #F5F5F5;
				border-radius: 20rpx;
				font-weight: bold;
				font-size: 36rpx;
				
			}
		}

		//
		.subordinate {
			width: 90vw;
			margin: 30rpx auto;

			.list {
				width: 100%;
				height: 166rpx;
				background-color: #FFFFFF;
				margin-bottom: 20rpx;
				border-radius: 10rpx;

				.list_l {
					width: 40rpx;
					height: 40rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.list_c {
					width: 70%;

					image {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;
					}

					.list_c_r {
						margin-left: 20rpx;
						color: #272823;

						.name {
							font-size: 28rpx;
							font-weight: bold;
						}

						.time {
							font-size: 24rpx;
							font-weight: 500;
						}
					}

					.list_r {
						width: 30rpx;
						height: 30rpx;
					}
				}
			}
		}
	}
</style>
